﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AForge.Neuro;

namespace AIthin.Model
{
    public partial class NewNetworkForm : Form
    {
        public NewNetworkForm()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
           

            String Name = textBoxName.Text + ".nw";

            switch (comboBoxNetworkArt.SelectedIndex)
            {
                case 0:
                    break;
                default:
                    break;
            }


            double SV = double.Parse(textBoxSigma.Text);
            IActivationFunction af;

            switch (comboBoxActivaFunk.SelectedIndex)
            {
                case 0: af = new BipolarSigmoidFunction(SV);
                    break;
                case 1: af = new SigmoidFunction(SV);
                    break;
                default: af = new BipolarSigmoidFunction(SV);
                    comboBoxActivaFunk.SelectedIndex = 1;
                    break;
            }

            int Population = int.Parse(textBoxPopulation.Text);

            int NCount = int.Parse(textBoxNeurons.Text);
            // output number will be set in InitLearning
            int Layers = int.Parse(textBoxLayers.Text);
            int[] neuronsCount = new int[Layers + 1];
            for (int i = 0; i < Layers; i++)
                neuronsCount[i] = NCount;
            neuronsCount[Layers] = int.Parse(textBoxOutputs.Text);

            int Size = int.Parse(comboBoxSize.SelectedItem.ToString());

            ActivationNetwork network  = new ActivationNetwork(af, Size*Size,  neuronsCount);

            network.Save(AIthin.Model.Properties.Settings.Default.WorkingPath + "\\" + Name);
            MessageBox.Show("Network " + Name + " saved.");
            this.Hide();

            NeuroNetworkForm NF1 = new NeuroNetworkForm();
            NF1.MdiParent = this.MdiParent;

            NF1.LoadNetworkFile(AIthin.Model.Properties.Settings.Default.WorkingPath, Name);
            NF1.Show();
            this.Close();

        }
    }
}
